/*
 * *
 *  * Copyright (c) iwindplus Technologies Co., Ltd.2024-2030, All rights reserved.
 *
 *
 */

package com.iwindplus.boot.operate.listener;

import cn.hutool.extra.spring.SpringUtil;
import com.iwindplus.boot.operate.domain.dto.OperateLogDTO;
import com.iwindplus.boot.operate.domain.event.OperateLogEvent;
import com.iwindplus.boot.operate.service.OperateLogService;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;

/**
 * 操作日志监听器.
 *
 * @author zengdegui
 * @since 2025/03/21 21:51
 */
@Slf4j
public class OperateLogListener {

    /**
     * 操作日志监听保存数据.
     *
     * @param operateLogEvent 日志事件
     */
    @Async
    @EventListener(OperateLogEvent.class)
    public void onApplicationEvent(OperateLogEvent operateLogEvent) {
        final OperateLogDTO logData = operateLogEvent.getOperateLogData();
        if (Objects.isNull(logData)) {
            return;
        }
        final OperateLogService operateLogService = SpringUtil.getBean(OperateLogService.class);
        operateLogService.save(logData);
    }
}
